package org.wu.acw.server.controller;



import org.wu.framework.authorization.platform.domain.model.sys.menu.SysMenu;
import org.wu.framework.authorization.platform.domain.model.sys.role.SysRole;
import org.wu.framework.authorization.platform.domain.model.sys.user.SysUser;
import org.wu.framework.web.spring.EasyController;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;
import org.wu.acw.core.domain.uo.AcwInstanceUo;
import org.wu.acw.core.domain.uo.AcwSchemaUo;
import org.wu.acw.core.domain.uo.AcwTableColumnUo;
import org.wu.acw.core.domain.uo.AcwTableUo;
import org.wu.acw.server.application.dto.ShortcutsDataDTO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;

@Tag(name = "快捷方式")
@EasyController("/shortcuts")
public class AcwShortcutsController {

    private final LazyLambdaStream lazyLambdaStream;

    public AcwShortcutsController(LazyLambdaStream lazyLambdaStream) {
        this.lazyLambdaStream = lazyLambdaStream;
    }

    /**
     * 查询快捷方式数据
     *
     * @return
     */
    @ApiOperation(value = "查询快捷方式数据")
    @GetMapping("/data")
    public Result<ShortcutsDataDTO> data() {
        // 查询菜单数量、用户数量、角色数量
        ShortcutsDataDTO shortcutsDataDTO = new ShortcutsDataDTO();
        Long menuNum = lazyLambdaStream.count(LazyWrappers.
                <SysMenu>lambdaWrapper()
                .eq(SysMenu::getIsDeleted, false)
        );
        Long sysUserNum = lazyLambdaStream.count(LazyWrappers.
                <SysUser>lambdaWrapper()
                .eq(SysUser::getIsDeleted, false)
        );
        Long roleNum = lazyLambdaStream.count(LazyWrappers.
                <SysRole>lambdaWrapper()
                .eq(SysRole::getIsDeleted, false)
        );
        Long instanceNum = lazyLambdaStream.count(LazyWrappers.
                <AcwInstanceUo>lambdaWrapper()
                .eq(AcwInstanceUo::getIsDeleted, false)
        );
        Long schemaNum = lazyLambdaStream.count(LazyWrappers.
                <AcwSchemaUo>lambdaWrapper()
                .eq(AcwSchemaUo::getIsDeleted, false)
        );
        Long tableNum = lazyLambdaStream.count(LazyWrappers.
                <AcwTableUo>lambdaWrapper()
                .eq(AcwTableUo::getIsDeleted, false)
        );
        Long tableColumnNum = lazyLambdaStream.count(LazyWrappers.
                <AcwTableColumnUo>lambdaWrapper()
                .eq(AcwTableColumnUo::getIsDeleted, false)
        );
        shortcutsDataDTO.setMenuNum(menuNum);
        shortcutsDataDTO.setUserNum(sysUserNum);
        shortcutsDataDTO.setRoleNum(roleNum);
        shortcutsDataDTO.setInstanceNum(instanceNum);
        shortcutsDataDTO.setSchemaNum(schemaNum);
        shortcutsDataDTO.setTableNum(tableNum);
        shortcutsDataDTO.setTableColumnNum(tableColumnNum);

        return ResultFactory.successOf(shortcutsDataDTO);
    }

}
